<template>
  <div ref="t">
    <HomePanel title="人气推荐" sub-title="人气爆款 不容错过">
      <template #right><XtxMore path="/" /></template>
      <ul ref="pannel" class="goods-list">
        <li v-for="item in goods" :key="item.id">
          <RouterLink :to="`/xtxgoods/${item.id}`">
            <!--
              img一旦指定了src之后，就会发请求求图片
              懒加载思路：
              1. 给img中指定一个别的属性名（url），值就是图片地址
              2. 当img进入可视区，把url值赋给img的src，这样，就可以去请求图片了

             通过自定义指令来实现
              <img v-imgLazy="真实图片的地址..." alt="">
             -->
            <!-- <img :src="item.picture" alt=""> -->
            <img v-imgLazy="item.picture" alt="" />
            <p class="name">{{ item.title }}</p>
            <p class="desc">{{ item.alt }}</p>
          </RouterLink>
        </li>
      </ul>
    </HomePanel>
  </div>
</template>

<script>
import { ref } from 'vue'
import HomePanel from './HomePanel.vue'
import { findHot } from '@/api/main.js'
// import { useIntersectionObserver } from '@vueuse/core'
import { useLazyData } from '@/compositions/index.js'
export default {
  name: 'HomeNew',
  components: { HomePanel },
  setup() {
    const goods = ref([])
    const fn = () => {
      // 发送请求
      findHot().then(data => {
        goods.value = data.result
      })
    }
    const t = useLazyData(fn)
    return { goods, t }
  }
}
</script>

<style scoped lang="less">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 426px;
  li {
    width: 306px;
    height: 406px;
    .hoverShadow();
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
